// GameBrowserLeftPanel.cpp : implementation file
//

#include "stdafx.h"
#include "../GameBrowser.h"
#include "GameBrowserLeftPanel.h"
#include "GameBrowserUtil.h"


// CGameBrowserLeftPanel

IMPLEMENT_DYNAMIC(CGameBrowserLeftPanel, CGameBrowserLeftSizedPanel)

CGameBrowserLeftPanel::CGameBrowserLeftPanel()
{

}

CGameBrowserLeftPanel::~CGameBrowserLeftPanel()
{
}


BEGIN_MESSAGE_MAP(CGameBrowserLeftPanel, CGameBrowserLeftSizedPanel)
	ON_WM_CREATE()
    ON_WM_DESTROY()
    ON_WM_SIZE()
	ON_MESSAGE(WM_SIZEPARENT, &CGameBrowserLeftPanel::OnSizeParent)   
END_MESSAGE_MAP()

BOOL CGameBrowserLeftPanel::CreateLeftPanel( CWnd *pParent,UINT nID )
{
	CString strWndClass(::AfxRegisterWndClass(CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW,     
		LoadCursor(0,IDC_ARROW), ::GetSysColorBrush(COLOR_BTNFACE)));   

	DWORD dwStyle = WS_CHILD|WS_VISIBLE;  
	BOOL bRet = CWnd::Create(strWndClass,L"CGameBrowserLeftPanel",dwStyle,CRect(0,0,0,0),pParent,nID);

	return bRet;	
}

int CGameBrowserLeftPanel::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
   BOOL bRet = m_wndSearchControl.CreateGameBrowserLeftPanelSerchControl(this,GM_PANEL_LEFT_SERCH_ID);

   ASSERT(bRet);

   bRet = m_wndTreeViewControl.CreateLeftPanelTreeViewControl(this,GM_PANEL_LEFT_TREEVIEW_ID);

   ASSERT(bRet);


	return CGameBrowserLeftSizedPanel::OnCreate(lpCreateStruct);
}

void CGameBrowserLeftPanel::OnSize(UINT nType, int cx, int cy)
{
    int controlWidth = cx - g_CEdgeWidth;
    if (controlWidth > 0)
    {
        m_wndSearchControl.SetWindowPos(NULL,0,0,controlWidth,GM_LEFT_PANEL_SEARCH_HEIGHT,SWP_NOZORDER);

        m_wndTreeViewControl.SetWindowPos(NULL,0,GM_LEFT_PANEL_SEARCH_HEIGHT,controlWidth,cy - GM_LEFT_PANEL_SEARCH_HEIGHT,SWP_NOZORDER);
    }
    CGameBrowserLeftSizedPanel::OnSize(nType, cx, cy); 
}

LRESULT CGameBrowserLeftPanel::OnSizeParent( WPARAM wParam, LPARAM lParam )
{

	AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;

	int n_oriWidth = lpLayout->rect.right - lpLayout->rect.left;
	int n_oriHeight = lpLayout->rect.bottom - lpLayout->rect.top;

	CRect rcWinPos;

	int XWidth = m_cContainerSize.cx;

	rcWinPos.top = lpLayout->rect.top;
	rcWinPos.bottom = lpLayout->rect.bottom;//+ SHP_COLLAPSEWIDTH;
	rcWinPos.left = lpLayout->rect.left;
	rcWinPos.right = rcWinPos.left + XWidth;//lpLayout->rect.right;

	lpLayout->rect.left += XWidth;
	lpLayout->sizeTotal.cx -= XWidth;
	

	MoveWindow(rcWinPos.left,rcWinPos.top,rcWinPos.Width(),rcWinPos.Height(),TRUE);  


	return TRUE;    
}

void CGameBrowserLeftPanel::AfterSizeChanged()
{
    CWnd*pmfWnd = AfxGetMainWnd();
    CFrameWnd *pMainFrameWnd = (CFrameWnd*)(pmfWnd);
    pMainFrameWnd->RecalcLayout();
}

void CGameBrowserLeftPanel::OnDestroy() 
{
    m_wndSearchControl.DestroyWindow();
    m_wndTreeViewControl.DestroyWindow();
    CGameBrowserLeftSizedPanel::OnDestroy();
}
// CGameBrowserLeftPanel message handlers


